/**
 * 具有层级关系的单行结构对象转换成树形结构
 * @param {Array} data 需要进行递归成树形数组对象
 */

export function recursion(data){
    // console.log(data)
    function buildTree(items, parent = null) {
        return items
            .filter(item => item.PARENT === parent)
            .map(item => ({
                ...item,
                children: buildTree(items, item.ID)
            }))
   }
   let tree = buildTree(data)
//    console.log(tree)
   return tree    
}

export function recursionByKey(data,parKey,sonKey){
    // console.log(data)
    function buildTree(items, parent = null) {
        return items
            .filter(item => item[parKey] === parent)
            .map(item => ({
                ...item,
                children: buildTree(items, item[sonKey])
            }))
   }
   let tree = buildTree(data)
//    console.log(tree)
   return tree    
}